import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


// 常规方式
import HelloWorld from '@/components/HelloWorld'
import Index from '@/pages/Index'
import Detail from '@/pages/Detail'
import MeScroll from '@/pages/Mescroll'
// 路由表
const Routers = [
	{
		path: '/',
		name: 'Index',
		component: Index,
		meta: {
			title: '首页'
		}
	},
	{
		path: '/detail',
		name: 'Detail',
		component: Detail,
		meta: {
			title: '详情页',
			requireAuth: true
		}
	},
	{
		path: '/mescroll',
		name: 'MeScroll',
		component: MeScroll,
		meta: {
			title: '上拉刷新',
			requireAuth: true
		}
	}
];



// // 懒加载方式
// function loadView(view) {
// 	return () => import(/* webpackChunkName: "View-[request]" */ `@/pages/${view}.vue`)
// }
// // 路由表
// const Routers = [
// 	{
// 		path: '/',
// 		name: 'Index',
// 		component: loadView('Index'),
// 		meta: {
// 			title: '首页'
// 		}
// 	}
// ]











// 路由配置信息
const RouterConfig = {
	linkActiveClass: 'active',
	linkExactActiveClass: 'nav-item',
	mode: 'hash',
	routes: Routers
};

const router = new Router(RouterConfig);


router.beforeEach(function(to,from,next){
	// 修改页面标题
	window.document.title = to.meta.title;

	// 权限验证
	if ( to.meta.requireAuth ) {
		// alert('plase logo')
		next()
	} else {
		next()
	}

});

router.afterEach()




export default router;